/*
    This is a set of libraries to assist in OpenGl and Other Applications
    Copyright (C) 2008  The Modular Engine Team

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "consoleFunctions.h"
#include <windows.h>

namespace ModularEngine
{
	int initConsoleFunctions()
	{

		
		ADDCOMMAND( cFPS );
		ADDCOMMAND( cPRINTF );
		ADDCOMMAND( cQUIT );
		
		// help commands.
		ADDCOMMAND( cHELP );
		return 1;
	}

	void cPRINTF::init()
	{
		NEWARG( C_STRING );
	}

	void cPRINTF::operator ()()
	{
		ConsoleModule::getSingleton().sendCommand( ARG_S(0) );
		//ModularEngine::TestModule::getSingleton().consoleText->addText(  );
	}

	void cFPS::init()
	{
		NEWARG( C_NUMBER );
		bShowFPS = false;
	}

	void cFPS::operator () ()
	{
		if( ARG_N(0) == 0 )
			bShowFPS = false;
		else
			bShowFPS = true;		
	}

	void cQUIT::init()
	{
		
	}

	void cQUIT::operator ()()
	{
		EngineCore::getSingleton().stop();
	}

	void cHELP::init()
	{
		NEWARG( C_STRING );
	}

	void cHELP::operator () ()
	{
		std::string command = "printf \"Console Function Not Found\"";

		for( std::vector<CFunctor *>::iterator i = ConsoleModule::getSingleton().mConsoleFunctions.begin(); i != ConsoleModule::getSingleton().mConsoleFunctions.end(); i++ )
		{
			if( ARG_S(0) == (*i)->mFuncName )
			{
				// print help info
				//command = "printf \"";
				command = "Console>>\n\n-----------------------HELP-----------------------\n\nFUNCTION: `";
				command += ARG_S(0);
				command += "` [ ";
				for( std::vector<CArg>::iterator j = (*i)->mArgs.begin(); j != (*i)->mArgs.end(); j++ )
				{
					switch( j->mArgType )
					{
					case C_STRING:
						command += "STRING ";
						break;
					case C_NUMBER:
						command += "NUMBER ";
						break;
					}
				}

				command += "]\n\n--------------------------------------------------\n\nDESCRIPTION: \n";
				command += "Descriptions are not yet availiable.";

				break;
			}
		}

		//console( command );
		ConsoleModule::getSingleton().sendCommand( command );


	}

}